package xddq

import (
	"fmt"
	"time"
	D "websocket_apn/define"
	"websocket_apn/log"
	"websocket_apn/proto"
)

// 处理妖盟对决信息结果
func (xd *XdDriver) CheckUnionDuiJueAllInfoData(info D.UnionDuiJueAllInfo) {
	xd.UserData.UnionDuiJueFightCount = info.FightCount
	if info.FightCount > 0 {
		log.Infof("妖盟对决-对决妖盟[%s], 剩余攻击次数 %d", info.UName, info.FightCount)
		////查看高级列表
		//xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_DUEL_OPEN_LIST_VIEW, fmt.Sprintf("08 %s 10 03 18 01", info.ID)))
		//time.Sleep(20 * time.Second)
		////查看中级列表
		//xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_DUEL_OPEN_LIST_VIEW, fmt.Sprintf("08 %s 10 02 18 01", info.ID)))
		//time.Sleep(20 * time.Second)
		//查看低级列表
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_DUEL_OPEN_LIST_VIEW, fmt.Sprintf("08 %s 10 01 18 01", info.ID)))
		time.Sleep(20 * time.Second)
	} else {
		xd.StopTaskByID(proto.S_UNION_DUEL_OPEN_VIEW)
	}
}

// 处理妖盟对决人员信息结果
func (xd *XdDriver) CheckUnionDuiJueInfoData(allInfo []D.UnionDuiJueInfo) {
	selfCombatValue := xd.UserData.CurrentEquipmentInfo[1].CombatValue
	//需要更换分身
	switchCloneFlag := false
	if xd.UserData.EquipmentCloneFlag && xd.UserData.CurrentEquipmentIdx != 1 {
		switchCloneFlag = true
		xd.SwitchCloneMu.Lock()
		xd.SwitchClone(1)
	}
	fightCount := 0
	for _, info := range allInfo {
		if xd.UserData.UnionDuiJueFightCount > 0 && info.FightCount > 0 && (info.CombatValue*10 < selfCombatValue*7) {
			log.Infof("妖盟对决-当前攻击力%s 开始攻击[%s] 妖力:%s", D.GetCombatValueDesc(selfCombatValue), info.Name, D.GetCombatValueDesc(info.CombatValue))
			xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_DUEL_FIGHT, fmt.Sprintf("08 %s 11 %s", info.ID, info.Data)))
			fightCount++
			time.Sleep(time.Second)
		}
		if fightCount >= 6 {
			break
		}
	}
	if switchCloneFlag {
		xd.SwitchCloneMu.Unlock()
	}
}
